var app = getApp();
var commonURL = app.data.baseURL;
var commonURLYY = app.data.newURL;
var jielong = app.data.jielong;
const commonURLXX = app.data.XCX_PAY;
Page({
  data: {
    remind: '加载中',
    angle: 0,
    userInfo: {}
  },
  goToIndex: function () {
    var that = this;
    wx.request({//获取是否团长
      url: commonURL + 'op=is_area_commander_copy',
      data: { "openid": wx.getStorageSync('openid'), "uniacid": app.data.GZHid },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res)
        if (res.data.status == 1) {
          wx.setStorage({
            key: 'isTz',
            data: 1,
          })
          wx.setStorage({
            key: 'tzInfo',
            data: res.data.data,
          })
          wx.setStorage({
            key: 'noright',
            data: false,
          })
        } else if (res.data.status == 0) {
          wx.setStorage({
            key: 'isTz',
            data: 0,
          })
          wx.setStorage({
            key: 'noright',
            data: true,
          })
        } else {
          wx.setStorage({
            key: 'isTz',
            data: 1,
          })
          wx.setStorage({
            key: 'tzInfo',
            data: res.data.data,
          })
          wx.setStorage({
            key: 'noright',
            data: false,
          })
        }
        if (that.data.status == 2) {
          wx.redirectTo({
            url: '../jielong/Tindex/Tindex',
          })
        } else if (that.data.status == 1) {
          wx.switchTab({
            url: '../index/index',
          })
        } else {
          wx.showToast({
            title: '未在后台设置',
          })
        }

      }
    })
  },
  onLoad: function () {
    console.log(2)
    var that = this;
  },
  onShow: function () {
    var that = this;
    wx.request({
      url: jielong + 'action=getSet',
      data: {
        uniacid: app.data.GZHid,
      },
      method: "POST",
      success: function (res) {
        console.log(res)
        that.setData({
          status: res.data.data.pick_status,
          business: res.data.msg,
          title_picture: res.data.data.title_picture,
          middle_picture: res.data.data.middle_picture
        })
        wx.setStorage({
          key: 'business',
          data: res.data.msg,
        })
        wx.setStorage({
          key: 'business_address',
          data: res.data.msg.address,
        })
        if (res.data.data.group_tel) {
          var group_tel = res.data.data.group_tel;
          wx.setStorage({
            key: 'group_tel',
            data: group_tel,
          })
        }
        if (res.data.data.group_tel) {
          var join_tel = res.data.data.join_tel;
          wx.setStorage({
            key: 'join_tel',
            data: join_tel,
          })
        }
        if (res.data.data.group_tel) {
          var supplier_tel = res.data.data.supplier_tel;
          wx.setStorage({
            key: 'supplier_tel',
            data: supplier_tel,
          })
        }

        if (res.data.data.pick_status == "2") {
          that.setData({
            background: '#64b008'
          })
          wx.setNavigationBarColor({
            frontColor: '#ffffff',
            backgroundColor: '#64b008',
          })
        } else {
          that.setData({
            background: '#dc6992'
          })
          wx.setNavigationBarColor({
            frontColor: '#ffffff',
            backgroundColor: '#dc6992',
          })
        }
        let userInfo = wx.getStorageSync('userInfo')
        console.log(that.data)
        console.log(that.data.business)
        if (!userInfo) {
          wx.navigateTo({
            url: "/pages/authorization/authorization?img=" + JSON.stringify(that.data.business) + '&status=' + that.data.status
          })
        } else {
          that.setData({
            userInfo: userInfo
          })
        }
      }
    })

  },
  onReady: function () {
    var that = this;
    setTimeout(function () {
      that.setData({
        remind: ''
      });
    }, 1000);
    wx.onAccelerometerChange(function (res) {
      var angle = -(res.x * 30).toFixed(1);
      if (angle > 14) { angle = 14; }
      else if (angle < -14) { angle = -14; }
      if (that.data.angle !== angle) {
        that.setData({
          angle: angle
        });
      }
    });
  }
});
